#include "ringQueue.hpp"
#include <pthread.h>
#include <time.h>
using namespace std;

void *consumer(void *args)
{
    ringQueue<int> *rq = static_cast<ringQueue<int> *>(args);
    // 消费->打印环形队列中的int
    while (1)
    {
        int data = 0;
        rq.pop(data);
        cout << "consumer pop:" << data << endl;
    }
}
void *productor(void *args)
{
    ringQueue<int> *rq = static_cast<ringQueue<int> *>(args);
    // 生产->随机数(1-100)
    while (1)
    {
        
        rq->push(rand() % 100 + 1);
    }
}

int main()
{
    srand(time(0));
    ringQueue<int> *rq;
    // 两个线程代表生产者消费者进行生产活动和消费活动
    pthread_t p;
    pthread_t c;

    pthread_create(&p, nullptr, consumer, (void *)rq);
    pthread_create(&c, nullptr, productor, (void *)rq);

    pthread_join(p, nullptr);
    pthread_join(c, nullptr);

    return 0;
}